<template>
	<view>
		<pageheader :setting="settingdata"></pageheader>
		<go-top :scrollTop="scrollTop"></go-top>
		<view class="listbox">
			<view class="listone" v-for="(item,index) in list" :key="index" @click="isclick(item.id,item.title)">
				<text :class="item.id==relevance.id?'iconfont icon-roundcheck on':'iconfont icon-xuanzhongyuandian'"></text>
				<image :src="item.image" mode="aspectFill"></image>
				<view class="listinfo">
					<text class="clamp1 name">{{item.title}}</text>
					<view class="hot_info">
						<view class="hot_price"><text>￥</text>{{item.money}}<text>/{{item.unit}}</text></view>
						<text class="hot_looks">{{item.view}}人查看</text>
					</view>
					<view class="listone_pos">{{item.city}}</view>
				</view>
			</view>
		</view>
		<view class="submitbox">
			<view class="sbumitbtn" @click="submit">取消关联</view>
		</view>
		<view class="nomore" v-if="nomore&&list.length>0">—— · 没有更多了 · ——</view>
	</view>
</template>

<script>
	var _this, $paginator;
	export default {
		data() {
			return {
				settingdata: {
					name: '关联供应货品',
					bgColor: '#fff',
					titleColor: '#000000',
					showNav: true,
					showTypes: 0,
					position: "contactshops"
				},
				list: [],
				relevance:{}
			}
		},
		onLoad(options) {
			_this = this
			_this.relevance.id=options.id?options.id:""
			_this.relevance.name=options.name?options.name:""
			$paginator = new _this.$paginator(_this.$api)
			_this.getdata(true)
		},
		//监听页面滚动
		onPageScroll(res) {
			this.scrollTop = res.scrollTop
		},
		onReachBottom: function() {
			$paginator.nextPager(() => {
				_this.getdata()
			})
		},
		methods: {
			getdata: function(firstLoad = false) {
				$paginator.getData('joingoodsList', {}, (data) => {
					if (firstLoad) {
						_this.list = data.list ? data.list : []
					} else {
						_this.list = _this.list.concat(data.list)
					}
					_this.nomore = data.nomore
				})
			},
			isclick(id,name){
				let relevance={}
				if(_this.relevance.id==id){
					relevance.id=""
					relevance.name=""
				}else{
					relevance.id=id
					relevance.name=name
				}
				_this.relevance=relevance
				uni.setStorageSync("relevance",relevance)
				wx.navigateBack({delta: 1})
			},
			submit(){
				uni.setStorageSync("relevance",{})
				wx.navigateBack({delta: 1})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.listbox {
		border-top: 10rpx solid #F2F2F2;
		display: flex;
		flex-direction: column;
		padding: 0 41rpx;
		padding-bottom: 118rpx;
		padding-bottom: calc(env(safe-area-inset-bottom) + 118rpx);

		.listone {
			display: flex;
			flex-direction: row;
			align-items: center;
			margin-top: 39rpx;

			.iconfont {
				font-size: 40rpx;
				color: #A7A7A7;
			}

			.on {
				color: #38BE8C;
			}

			image {
				margin-left: 24rpx;
				width: 180rpx;
				height: 180rpx;
				border-radius: 10rpx;
			}

			.listinfo {
				margin-left: 19rpx;
				width: 360rpx;
				display: flex;
				flex-direction: column;

				.name {
					color: #222222;
					font-size: 30rpx;
				}

				.hot_info {
					margin-top: 21rpx;
					display: flex;
					flex-direction: row;
					align-items: center;

					.hot_price {
						font-size: 30rpx;
						color: #F73F3F;
						font-weight: bold;
						display: flex;
						flex-direction: row;
						align-items: flex-end;

						text {
							font-weight: normal;
							font-size: 24rpx;
						}
					}

					.hot_looks {
						font-size: 22rpx;
						color: #999999;
						margin-left: 16rpx;
					}
				}

				.listone_pos {
					margin-top: 26rpx;
					color: #999999;
					font-size: 22rpx;
				}
			}
		}
	}

	.submitbox {
		padding: 10rpx 35rpx 10rpx 35rpx;
		padding: 10rpx 35rpx calc(env(safe-area-inset-bottom) + 10rpx) 35rpx;
		background-color: #fff;
		width: 100%;
		position: fixed;
		bottom: 0;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;

		.sbumitbtn {
			width: 680rpx;
			height: 90rpx;
			background: linear-gradient(86deg, #38BE8C, #05ADBB);
			border-radius: 45rpx;
			line-height: 90rpx;
			text-align: center;
			color: #fff;
			font-size: 34rpx;
			font-weight: bold;
		}
	}
</style>
